package com.example.datasourcedemo.utils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class Test02 {


    public static void main(String[] args) {

        Map<String, Object> map1 = new HashMap<>();
        map1.put("username", "chen1");
        map1.put("downreason", "0");
        map1.put("stoptime", "0800");

        Map<String, Object> map2 = new HashMap<>();
        map2.put("username", "chen2");
        map2.put("downreason", "2");
        map2.put("stoptime", "0900");

        Map<String, Object> map3 = new HashMap<>();
        map3.put("username", "chen3");
        map3.put("downreason", "3");
        map3.put("stoptime", "1000");

        Map<String, Object> map4 = new HashMap<>();
        map3.put("username", "chen3");
        map3.put("downreason", "2");
        map3.put("stoptime", "1010");

        List<Map<String, Object>> objects = new ArrayList<>();
        objects.add(map1);
        objects.add(map2);
        objects.add(map3);
        objects.add(map4);

        Map<Object, Long> username = objects.stream().collect(Collectors.groupingBy(map -> map.get("username"), Collectors.counting()));

        System.out.println(username.toString());

    }
}
